﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import flash.net.*;
    import Engine.*;

    public class Market extends SlotDialog {

        public static const COST_COINS:String = "coins";
        public static const COST_CASH:String = "cash";
        public static const COST_BOTH:String = "both";
        private static const NUM_SLOTS:int = 4;
        protected static const NUM_SUBSLOTS:int = 6;

        private static var m_soundLoaded:Boolean = false;

        private const MARKET_COUNTER:String = "market";
        private const MASTERY_BAR_MAX_WIDTH:int = 54;
        private const OUTOFRANGE:String = "outofrange";
        protected const SHOW_LIMITED_CLOCK:Boolean = false;

        private var m_viewSource:String = "unknown";
        private var m_lastClickedType:String = "initial";
        private var m_iconOffset:int;
        private var m_costOffset:int;
        private var m_currentUpState:String;
        protected var m_currentType:String = "tool";
        protected var m_currentSubType:String = "all";
        protected var m_allCurrentSubTypes:XMLList;
        protected var m_subTypeIndex:int = 1;
        private var m_xpInitY:Number;
        protected var topButtons:Object;
        protected var subcatButtons:Object;
        private var m_progBarTooltips:Array;
        private var m_popFeedFlag:Boolean = false;
        private var m_comingSoon:Class;
        private var m_soonPopup:MovieClip;
        private var m_buyTileNumber:int = -1;
        private var m_tileLoaders:Array;
        private var m_whatIsThisDialog:WhatIsThisPopup = null;
        private var m_rewardName:String = "";
        private var m_rewardLink:String = "";
        protected var m_icons:Array;
        protected var m_defaultIcon:String;
        protected var m_showLimitedIcons:Boolean = true;
        private var m_onCloseClickCallback:Function = null;
        protected var specialItemsSortOrder:Array;
        protected var experimentObject:Object;

        public function Market(_arg1:String="unknown", _arg2:String="tool", _arg3:String="all"){
            this.m_currentUpState = GenericButton.UPSTATE;
            this.m_progBarTooltips = new Array();
            this.m_tileLoaders = new Array(NUM_SLOTS);
            this.m_icons = new Array();
            this.specialItemsSortOrder = new Array();
            if (!m_soundLoaded){
                this.loadPlantingSounds();
            };
            this.m_viewSource = _arg1;
            this.m_currentType = _arg2;
            this.m_currentSubType = _arg3;
            m_dialogAsset = "assets/dialogs/FV_Market_Mega.swf";
            super();
        }
        override protected function showTween():void{
            this.mouseEnabled = (this.mouseChildren = false);
            this.visible = true;
            centerPopup();
            var contentClip:* = (m_content as MovieClip);
            MovieClipUtil.playAndStop(contentClip, 1, -1, false, function ():void{
                this.mouseEnabled = (this.mouseChildren = true);
            });
        }
        override protected function hideTween(_arg1:Function):void{
            var _local2:MovieClip;
            this.mouseEnabled = (this.mouseChildren = false);
            if (m_content == null){
                if (_arg1 != null){
                    _arg1();
                };
            } else {
                _local2 = (m_content as MovieClip);
                MovieClipUtil.playBackwardsAndStop(_local2, -1, 1, false, _arg1);
            };
            Sounds.play("dialogClose");
        }
        public function setCloseClickCallback(_arg1:Function):void{
            this.m_onCloseClickCallback = _arg1;
        }
        override protected function getNumSlots():int{
            return (NUM_SLOTS);
        }
        override protected function onLoadComplete():void{
            var icon:* = null;
            var objectXML:* = null;
            var btn_mc:* = null;
            var gb:* = null;
            var newText:* = null;
            var btnName:* = null;
            var subText:* = null;
            var tooltip:* = null;
            var mc:* = null;
            m_window = (m_loader.content as MovieClip);
            this.topButtons = new Array();
            this.subcatButtons = new Array();
            var icons:* = Global.gameSettings.getLimitedIcons();
            for each (icon in icons.icon) {
                this.m_icons.push(icon.@name.toString());
            };
            if (((icons.@defaultIcon) && (!((icons.@defaultIcon.toString() == ""))))){
                this.m_defaultIcon = icons.@defaultIcon.toString();
            };
            var objects:* = Global.gameSettings.getMenuItems();
            this.specialItemsSortOrder = this.xmlListToArray(objects, "type");
            var cntr:* = 1;
            var objectIdx:* = 0;
            while (objectIdx < objects.length()) {
                objectXML = objects[objectIdx];
                btn_mc = m_window[(("cat" + cntr) + "_bt")];
                cntr = (cntr + 1);
                if (btn_mc != null){
                    gb = new GenericButton(btn_mc, this.onMenuBarClick);
                    gb.m_overlay.name = (objectXML.@type + "_bt");
                    gb.enableHitState(true);
                    this.topButtons[objectXML.@type] = gb;
                    newText = ZLoc.t("Dialogs", (objectXML.@type + "_menu"));
                    gb.text = newText;
                };
                if (this.m_showLimitedIcons){
                    this.checkTopRowLimitedIcon(objectXML, btn_mc);
                };
                objectIdx = (objectIdx + 1);
            };
            if (((m_window.special_bt) && ((m_window.special_bt.visible == true)))){
                if (this.m_showLimitedIcons){
                    this.initializeSpecialButton();
                } else {
                    m_window.special_bt.visible = false;
                };
            };
            m_window.close_bt.addEventListener(MouseEvent.CLICK, this.onCloseClick);
            this.m_allCurrentSubTypes = Global.gameSettings.getSubMenuItemsByMenuType(this.m_currentType);
            var i:* = 1;
            while (i <= NUM_SUBSLOTS) {
                btnName = (("subcat" + i) + "_bt");
                btn_mc = (m_window[btnName] as MovieClip);
                gb = new GenericButton(btn_mc, this.onSubMenuBarClick);
                gb.m_overlay.name = (("subcat" + i.toString()) + "_bt");
                gb.enableHitState(true);
                this.subcatButtons[btnName] = gb;
                i = (i + 1);
            };
            var indx:* = Math.min((this.m_allCurrentSubTypes.length() + 1), NUM_SUBSLOTS);
            var currentIndex:* = 1;
            i = 2;
            while (i <= indx) {
                btnName = (("subcat" + i) + "_bt");
                gb = (this.subcatButtons[btnName] as GenericButton);
                subText = ZLoc.t("Dialogs", (this.m_allCurrentSubTypes[(i - 2)].@subtype + "_submenu"));
                if (this.m_allCurrentSubTypes[(i - 2)].@subtype == this.m_currentSubType){
                    currentIndex = i;
                };
                gb.text = subText;
                gb.enableHitState(true);
                i = (i + 1);
            };
            this.showSubCatButtons(this.m_allCurrentSubTypes);
            m_window.arrowLt_bt.addEventListener(MouseEvent.CLICK, onLtArrowClick);
            m_window.arrowRt_bt.addEventListener(MouseEvent.CLICK, onRtArrowClick);
            m_tiles.push(m_window.tile1, m_window.tile2, m_window.tile3, m_window.tile4);
            if (((m_tiles[0]) && (m_tiles[0].xp_tf))){
                this.m_xpInitY = m_tiles[0].xp_tf.y;
            };
            var tileId:* = 0;
            while (tileId < m_tiles.length) {
                tooltip = new ToolTip();
                tooltip.attachToolTip(m_tiles[tileId].progressBar_mc);
                tooltip.attachToolTip(m_tiles[tileId].progressTrack_mc);
                this.m_progBarTooltips.push(tooltip);
                tileId = (tileId + 1);
            };
            removeTiles();
            this.m_lastClickedType = "";
            this.pushNewData(this.m_currentType, this.m_currentSubType);
            this.onMenuBarClick(null, this.m_currentType, this.m_currentSubType);
            gb = (this.subcatButtons["subcat1_bt"] as GenericButton);
            gb.text = "All";
            gb = (this.subcatButtons[(("subcat" + currentIndex) + "_bt")] as GenericButton);
            gb.state = GenericButton.HITSTATE;
            var compIdx:* = 0;
            while ((((compIdx < NUM_SLOTS)) && ((compIdx < m_data.length)))) {
                this.addComponent(compIdx);
                compIdx = (compIdx + 1);
            };
            this.count("viewInitial");
            var index:* = 0;
            while (index < NUM_SLOTS) {
                mc = (m_tiles[index] as MovieClip);
                if (((mc.costGroup_mc) && (mc.icon))){
                    this.m_iconOffset = mc.icon.x;
                    this.m_costOffset = mc.costGroup_mc.x;
                };
                if (((!((this.m_costOffset == 0))) && (!((this.m_iconOffset == 0))))){
                    break;
                };
                index = (index + 1);
            };
            addChild(m_window);
            var button:* = this.topButtons[this.m_currentType];
            this.topButtons.forEach(function (_arg1:MovieClip):void{
                _arg1.state = GenericButton.UPSTATE;
            });
            button.state = GenericButton.HITSTATE;
        }
        protected function initializeSpecialButton():void{
            var _local2:GenericButton;
            var _local3:String;
            var _local1:MovieClip = m_window["special_bt"];
            if (_local1 != null){
                _local2 = new GenericButton(_local1, this.onMenuBarClick);
                _local2.m_overlay.name = "special_bt";
                _local2.enableHitState(true);
                this.topButtons["special"] = _local2;
                _local3 = ZLoc.t("Dialogs", "special_menu");
                _local2.text = _local3;
            };
        }
        protected function checkTopRowLimitedIcon(_arg1:XML, _arg2:MovieClip):void{
            var indx:* = 0;
            var item:* = null;
            var startDate:* = NaN;
            var endDate:* = NaN;
            var iconClassName:* = null;
            var classType:* = null;
            var andrewObj:* = null;
            var displayIcon:* = null;
            var objectXML:* = _arg1;
            var btn_mc:* = _arg2;
            if (objectXML.limitedIcon.length() > 0){
                indx = 0;
                for (;indx < objectXML.limitedIcon.length();(indx = (indx + 1))) {
                    item = objectXML.limitedIcon[indx];
                    if (((item.@startDate) && (!((item.@startDate.toString() == ""))))){
                        startDate = Utilities.dateToNumber(item.@startDate.toString());
                        endDate = Utilities.dateToNumber(item.@endDate.toString());
                        if ((((startDate <= GlobalEngine.getTimer())) && ((endDate >= GlobalEngine.getTimer())))){
                            iconClassName = item.@className;
                            andrewObj = getDefinitionByName(iconClassName);
                            //unresolved jump
                            var _slot1:* = e;
                            continue;
                            classType = (andrewObj as Class);
                            if (classType){
                                displayIcon = new (classType)();
                                if (displayIcon){
                                    m_window.addChild(displayIcon);
                                    if (item.@iconScale.toString() != ""){
                                        displayIcon.scaleX = (displayIcon.scaleY = parseFloat(item.@iconScale.toString()));
                                    };
                                    displayIcon.x = (((btn_mc.x + btn_mc.width) - (displayIcon.width / 2)) - 5);
                                    displayIcon.y = ((btn_mc.y - ((btn_mc.height / 2) * 0)) - (displayIcon.height / 2));
                                };
                            };
                        };
                    };
                };
            };
        }
        protected function pushNewData(_arg1:String, _arg2:String="all"):void{
            var _local3:GenericButton;
            var _local7:XMLList;
            var _local8:Array;
            var _local10:int;
            var _local11:int;
            var _local12:Object;
            var _local13:XML;
            var _local14:Boolean;
            if (((((this.m_currentType) && (!((this.m_currentUpState == null))))) && (!((this.m_currentType == _arg1))))){
                _local3 = this.topButtons[this.m_currentType];
                _local3.state = GenericButton.UPSTATE;
            };
            var _local4:Array = [];
            var _local5:Array = [];
            this.experimentObject = null;
            m_data = [];
            this.m_currentType = _arg1;
            m_tileSet = 0;
            _local3 = (this.topButtons[_arg1] as GenericButton);
            this.m_currentUpState = _local3.state;
            var _local6:int = Global.player.homeIslandSize;
            if (_arg1 == "special"){
                _local7 = Global.gameSettings.getSpecialItems();
                _local10 = 1;
                _local11 = 0;
                while (_local11 < _local7.length()) {
                    var _temp1 = _local10;
                    _local10 = (_local10 + 1);
                    _local7[_local11].@sortPriority = _temp1;
                    _local11++;
                };
                _local8 = this.xmlListToArray(_local7);
                _local8.sort(this.compareSpecialItems);
            } else {
                _local7 = Global.gameSettings.getItemsByTypeXML(_arg1, _arg2);
                _local8 = this.xmlListToArray(_local7);
            };
            var _local9:int;
            while (_local9 < _local8.length) {
                _local12 = new Object();
                _local13 = _local8[_local9];
                this.populateObjectXML(_local12, _local13);
                _local14 = this.determineItemVisibility(_arg1, _local12, _local13, _local6);
                if (_local14){
                    if (_local12.isMysteryItem){
                        if (_local12.limitedTimeLeft){
                            if (_local12.limitedTimeLeft != this.OUTOFRANGE){
                                _local4 = this.addObjectToArray(_local12, _local4);
                            };
                        } else {
                            _local4 = this.addObjectToArray(_local12, _local4);
                        };
                    } else {
                        if (_local12.limitedTimeLeft){
                            if (_local12.limitedTimeLeft != this.OUTOFRANGE){
                                _local4 = this.addObjectToArray(_local12, _local4);
                            };
                        } else {
                            _local5 = this.addObjectToArray(_local12, _local5);
                        };
                    };
                };
                _local9++;
            };
            m_data = _local4.concat(_local5);
            if (this.experimentObject != null){
                m_data = [this.experimentObject].concat(m_data);
            };
            fixArrows();
        }
        protected function determineItemVisibility(_arg1:String, _arg2:Object, _arg3:XML, _arg4:int):Boolean{
            var _local5:Number;
            var _local10:Number;
            var _local11:Number;
            var _local12:Number;
            var _local6:Number = 0;
            var _local7:int = _arg2.cost;
            var _local8:Number = Math.floor((_local7 * Global.gameSettings.getNumber("sellBackRatio")));
            _local5 = Math.floor((_local7 * Global.gameSettings.getNumber("buyXpGainRatio")));
            _local6 = Math.max(_local5, Global.gameSettings.getNumber("buyXpGainMin"));
            if (_arg3.buyXp.toString() != ""){
                _local6 = _arg3.buyXp;
            };
            var _local9:Boolean;
            if (_arg1 == "special"){
                _arg1 = _arg3.@type;
            };
            switch (_arg1){
                case "tree":
                case "animal":
                    if (_arg3.@buyable == true){
                        if (_arg3.plantXp.toString() != ""){
                            _local6 = _arg3.plantXp;
                        } else {
                            _local6 = 0;
                        };
                        _arg2.xpGained = _local6;
                        if (((_arg3.@license) && ((_arg3.@license == -1)))){
                            _local10 = 0;
                            _local11 = (GlobalEngine.getTimer() / 1000);
                            if (Global.player.licenses.hasOwnProperty(_arg2.name.toString())){
                                _local10 = Global.player.licenses[_arg2.name.toString()];
                            };
                            _local12 = (_local10 - _local11);
                            if (((!((_local10 == 0))) && ((_local12 > 0)))){
                            } else {
                                _local9 = false;
                            };
                        };
                    } else {
                        _local9 = false;
                    };
                    break;
                case "change_farm":
                    _local9 = (((_arg3.@subtype == "expand_farm")) && ((_arg3.@size > _arg4)));
                    break;
                case "tool":
                    if (Global.player.licenses[String(_arg3.@name)]){
                        _local9 = false;
                    };
                    break;
                default:
                    _local6 = 0;
                    _arg2.coinYield = _local8;
                    _local9 = (_arg3.@buyable == true);
            };
            return (_local9);
        }
        public function addObjectToArray(_arg1:Object, _arg2:Array):Array{
            var _local3:Array = _arg2;
            if (_arg1.experiment){
                this.experimentObject = _arg1;
            } else {
                _arg2.push(_arg1);
            };
            return (_arg2);
        }
        protected function xmlListToArray(_arg1:XMLList, _arg2:String=""):Array{
            var _local4:XML;
            var _local3:Array = new Array();
            if (_arg2 == ""){
                for each (_local4 in _arg1) {
                    _local3.push(_local4);
                };
            } else {
                for each (_local4 in _arg1) {
                    _local3.push(String(_local4.attribute(_arg2)));
                };
            };
            return (_local3);
        }
        protected function compareSpecialItems(_arg1:XML, _arg2:XML):int{
            var _local5:int;
            var _local6:int;
            var _local7:int;
            var _local3:int;
            var _local4:int = this.compareMysteryStatus(_arg1, _arg2);
            if (_local4 == 0){
                _local5 = this.compareLimitedStartDates(_arg1, _arg2);
                if (_local5 == 0){
                    _local6 = this.compareSendButtonStatus(_arg1, _arg2);
                    if (_local6 == 0){
                        _local7 = this.compareTypeStatus(_arg1, _arg2);
                        if (_local7 == 0){
                            _local3 = this.compareSortPriority(_arg1, _arg2);
                        } else {
                            _local3 = _local7;
                        };
                    } else {
                        _local3 = _local6;
                    };
                } else {
                    _local3 = _local5;
                };
            } else {
                _local3 = _local4;
            };
            return (_local3);
        }
        protected function compareSortPriority(_arg1:XML, _arg2:XML):int{
            var _local3:int;
            var _local4:String = (_arg1.@sortPriority.toString() as String);
            var _local5:String = (_arg2.@sortPriority.toString() as String);
            if (_local4 < _local5){
                _local3 = -1;
            } else {
                if (_local4 > _local5){
                    _local3 = 1;
                };
            };
            return (_local3);
        }
        protected function compareTypeStatus(_arg1:XML, _arg2:XML):int{
            var _local3:int;
            var _local4:String = (_arg1.@type.toString() as String);
            var _local5:String = (_arg2.@type.toString() as String);
            if (this.specialItemsSortOrder.indexOf(_local4) < this.specialItemsSortOrder.indexOf(_local5)){
                _local3 = -1;
            } else {
                if (this.specialItemsSortOrder.indexOf(_local4) > this.specialItemsSortOrder.indexOf(_local5)){
                    _local3 = 1;
                };
            };
            return (_local3);
        }
        protected function compareSendButtonStatus(_arg1:XML, _arg2:XML):int{
            var _local3:int;
            var _local4:Boolean;
            var _local5:Boolean;
            if (((_arg1.@present) && ((_arg1.@present == true)))){
                _local4 = true;
            };
            if (((_arg2.@present) && ((_arg2.@present == true)))){
                _local5 = true;
            };
            if (((_local4) && (!(_local5)))){
                _local3 = -1;
            } else {
                if (((_local5) && (!(_local4)))){
                    _local3 = 1;
                };
            };
            return (_local3);
        }
        protected function compareLimitedStartDates(_arg1:XML, _arg2:XML):int{
            var _local4:Boolean;
            var _local5:Boolean;
            var _local6:Number;
            var _local7:Number;
            var _local3:int;
            if (((_arg1.limitedStart) && (!((_arg1.limitedStart.toString() == ""))))){
                _local4 = true;
            };
            if (((_arg2.limitedStart) && (!((_arg2.limitedStart.toString() == ""))))){
                _local5 = true;
            };
            if (((_local4) && (_local5))){
                _local6 = Utilities.dateToNumber(_arg1.limitedStart.toString());
                _local7 = Utilities.dateToNumber(_arg2.limitedStart.toString());
                if (_local6 < _local7){
                    _local3 = -1;
                } else {
                    if (_local6 > _local7){
                        _local3 = 1;
                    };
                };
            } else {
                if (((_local4) && (!(_local5)))){
                    _local3 = 1;
                } else {
                    if (((!(_local4)) && (_local5))){
                        _local3 = -1;
                    };
                };
            };
            return (_local3);
        }
        protected function compareMysteryStatus(_arg1:XML, _arg2:XML):int{
            var _local3:int;
            var _local4:Boolean;
            var _local5:Boolean;
            if (((_arg1.lootTable) && (!((_arg1.lootTable.toString() == ""))))){
                _local4 = true;
            };
            if (((_arg2.lootTable) && (!((_arg2.lootTable.toString() == ""))))){
                _local5 = true;
            };
            if (((_local4) && (!(_local5)))){
                _local3 = -1;
            } else {
                if (((_local5) && (!(_local4)))){
                    _local3 = 1;
                };
            };
            return (_local3);
        }
        protected function populateObjectXML(_arg1:Object, _arg2:XML):void{
            var _local3:Number;
            var _local4:Number;
            var _local5:Number;
            var _local6:String;
            _arg1.name = _arg2.@name;
            _arg1.localizedName = Global.gameSettings.getItemFriendlyName(_arg1.name);
            _arg1.cost = _arg2.cost;
            _arg1.requiredLevel = _arg2.requiredLevel;
            _arg1.type = _arg2.@type;
            _arg1.category = _arg2.@category;
            if (_arg2.@subtype){
                _arg1.subtype = _arg2.@subtype;
            };
            if (_arg2.child("unlockCost").length() > 0){
                _arg1.unlockCost = _arg2.unlockCost;
            };
            if (_arg2.coinYield){
                _arg1.coinYield = _arg2.coinYield;
            };
            if (_arg2.growTime){
                _arg1.harvestTime = _arg2.growTime;
            };
            if (((_arg2.capacity) && ((_arg2.@subtype == "storage")))){
                _arg1.capacity = _arg2.capacity;
            };
            if (((_arg2.capacity) && ((_arg2.@subtype == "shipping")))){
                _arg1.capacity = _arg2.capacity;
            };
            if (_arg2.sizeX){
                _arg1.sizeX = _arg2.sizeX;
            };
            if (_arg2.sizeY){
                _arg1.sizeX = _arg2.sizeY;
            };
            if (_arg2.minNeighbors){
                _arg1.minNeighbors = _arg2.minNeighbors;
            };
            if (_arg2.@unlock.toString() != ""){
                _arg1.unlock = _arg2.@unlock;
            } else {
                _arg1.unlock = Item.UNLOCK_LEVEL;
            };
            if (_arg2.cash){
                _arg1.cash = _arg2.cash;
            };
            if (_arg2.size){
                _arg1.size = _arg2.@size;
            };
            if (_arg2.@market.toString() != ""){
                _arg1.market = _arg2.@market;
            } else {
                _arg1.market = Market.COST_COINS;
            };
            if (_arg2.@experiment.toString() != ""){
                _arg1.experiment = _arg2.@experiment;
            };
            _arg1.whatIsThis = false;
            if (_arg2.@whatIsThis.toString() == "true"){
                _arg1.whatIsThis = true;
            };
            if (((_arg2.lootTable) && (!((_arg2.lootTable.toString() == ""))))){
                _arg1.isMysteryItem = true;
            } else {
                _arg1.isMysteryItem = false;
            };
            if (((_arg2.limitedIcon) && (!((_arg2.limitedIcon.toString() == ""))))){
                _arg1.limitedIcon = _arg2.limitedIcon.toString();
            } else {
                if (_arg1.isMysteryItem){
                    _arg1.limitedIcon = "";
                } else {
                    _arg1.limitedIcon = this.m_defaultIcon;
                };
            };
            _arg1.isPresent = false;
            if (((_arg2.@present) && ((_arg2.@present == true)))){
                _arg1.isPresent = true;
            };
            if (((_arg2.limitedStart) && (!((_arg2.limitedStart.toString() == ""))))){
                _local3 = Utilities.dateToNumber(_arg2.limitedStart.toString());
                if (((_arg2.limitedEnd) && (!((_arg2.limitedEnd.toString() == ""))))){
                    _local4 = Utilities.dateToNumber(_arg2.limitedEnd.toString());
                    if ((((_local3 <= GlobalEngine.getTimer())) && ((_local4 >= GlobalEngine.getTimer())))){
                        _local5 = (((_local4 - GlobalEngine.getTimer()) / 1000) / 3600);
                        if (_local5 < 1){
                            _local6 = ZLoc.t("Dialogs", "TimeLeftMinutes", {time:int((_local5 * 60))});
                        } else {
                            if (_local5 <= 24){
                                _local6 = ZLoc.t("Dialogs", "TimeLeftHours", {time:int(_local5)});
                            } else {
                                _local6 = ZLoc.t("Dialogs", "TimeLeftDays", {time:Math.round((_local5 / 24))});
                            };
                        };
                        _arg1.limitedTimeLeft = _local6;
                    } else {
                        _arg1.limitedTimeLeft = this.OUTOFRANGE;
                    };
                };
            };
        }
        override public function getDialogOffset():Point{
            return (new Point(-5, 5));
        }
        protected function isLimitedEdition(_arg1:int, _arg2:int=0):Boolean{
            var _local3:Boolean;
            if (Object(m_data[(_arg2 + _arg1)]).hasOwnProperty("limitedTimeLeft")){
                _local3 = true;
            };
            return (_local3);
        }
        protected function isMysteryItem(_arg1:int, _arg2:int=0):Boolean{
            return (Object(m_data[(_arg2 + _arg1)]).isMysteryItem);
        }
        protected function hasWhatIsThisButton(_arg1:int, _arg2:int=0):Boolean{
            var _local3:Boolean;
            if (((Object(m_data[(_arg2 + _arg1)]).whatIsThis) || (this.isMysteryItem(_arg2, _arg1)))){
                _local3 = true;
            };
            return (_local3);
        }
        protected function hideAllUIElements(_arg1:int):void{
            if (m_tiles[_arg1].brownBorder_mc != null){
                m_tiles[_arg1].brownBorder_mc.visible = false;
            };
            m_tiles[_arg1].stars_mc.visible = false;
            m_tiles[_arg1].progressBar_mc.visible = false;
            m_tiles[_arg1].progressTrack_mc.visible = false;
            m_tiles[_arg1].timeLeft_tf.visible = false;
            m_tiles[_arg1].locked_mc.visible = false;
            m_tiles[_arg1].locked_tf.visible = false;
            m_tiles[_arg1].yield_tf.visible = false;
            m_tiles[_arg1].growth_tf.visible = false;
            m_tiles[_arg1].xp_tf.visible = false;
            m_tiles[_arg1].whatisthis_mc.visible = false;
            m_tiles[_arg1].costGroup_mc.visible = false;
            m_tiles[_arg1].level_tf.visible = false;
            m_tiles[_arg1].neighbor_tf.visible = false;
            m_tiles[_arg1].add_neighbor_bt.visible = false;
            m_tiles[_arg1].buy_bt.visible = false;
            m_tiles[_arg1].greenexpires_tf.visible = false;
            m_tiles[_arg1].greenyield_tf.visible = false;
            m_tiles[_arg1].greengrowth_tf.visible = false;
            m_tiles[_arg1].greenxp_tf.visible = false;
            m_tiles[_arg1].buyAlt_bt.visible = false;
            m_tiles[_arg1].present_bt.visible = false;
            if (m_tiles[_arg1].whatisthis_bt != null){
                m_tiles[_arg1].whatisthis_bt.turnOff();
                m_tiles[_arg1].whatisthis_bt = null;
            };
        }
        protected function setupMasteryDisplay(_arg1:int, _arg2:int=0):void{
            var _local3:int;
            var _local4:int;
            if ((((m_data[(_arg2 + _arg1)].mastery == true)) && ((Global.player.level >= Global.gameSettings.getAttribute("masteryStartLevel", 15))))){
                m_tiles[_arg1].stars_mc.visible = true;
                m_tiles[_arg1].brownBorder_mc.visible = true;
                m_tiles[_arg1].progressBar_mc.visible = true;
                m_tiles[_arg1].progressTrack_mc.visible = true;
                this.m_progBarTooltips[_arg1].attachToolTip(m_tiles[_arg1].progressBar_mc);
                this.m_progBarTooltips[_arg1].attachToolTip(m_tiles[_arg1].progressTrack_mc);
                if (m_data[(_arg2 + _arg1)].masteryObject.hasAllMasteries()){
                    m_tiles[_arg1].stars_mc.gotoAndStop((m_data[(_arg2 + _arg1)].masteryObject.currentLevel + 2));
                    m_tiles[_arg1].progressBar_mc.width = this.MASTERY_BAR_MAX_WIDTH;
                    this.m_progBarTooltips[_arg1].toolTip = ZLoc.t("Dialogs", "Mastered");
                } else {
                    _local3 = m_data[(_arg2 + _arg1)].masteryObject.currentProgress;
                    _local4 = m_data[(_arg2 + _arg1)].masteryObject.totalCropsNeeded;
                    m_tiles[_arg1].stars_mc.gotoAndStop((m_data[(_arg2 + _arg1)].masteryObject.currentLevel + 2));
                    m_tiles[_arg1].progressBar_mc.width = ((_local3 / _local4) * this.MASTERY_BAR_MAX_WIDTH);
                    this.m_progBarTooltips[_arg1].toolTip = ZLoc.t("Dialogs", "MasteryProgress", {
                        curProgress:_local3,
                        total:_local4
                    });
                };
            };
        }
        protected function turnOnLimitedIcon(_arg1:String, _arg2:MovieClip):void{
            var _local4:MovieClip;
            var _local3:int;
            while (_local3 < this.m_icons.length) {
                _local4 = (_arg2.getChildByName(this.m_icons[_local3]) as MovieClip);
                if (_local4){
                    if (_arg1 == this.m_icons[_local3]){
                        _local4.visible = true;
                    } else {
                        _local4.visible = false;
                    };
                };
                _local3++;
            };
        }
        override protected function addComponent(_arg1:int, _arg2:int=0):void{
            var mc:* = null;
            var tileSet:* = 0;
            var url:* = null;
            var icon:* = null;
            var name:* = null;
            var licenseHeld:* = NaN;
            var currentTime:* = NaN;
            var delta:* = NaN;
            var neighborSuccess:* = false;
            var levelSuccess:* = false;
            var compId:* = _arg1;
            var index:int = _arg2;
            if (WhatIsThisPopup.describeDialogOpen){
                this.m_whatIsThisDialog.close();
            };
            if (((m_tiles) && (!((m_data[(index + compId)] == null))))){
                mc = (m_tiles[compId] as MovieClip);
                mc.addFrameScript(0, function ():void{
                    var _local2:GenericButton;
                    var _local3:String;
                    var _local4:Number;
                    var _local5:String;
                    var _local6:Number;
                    var _local7:String;
                    var _local8:GenericButton;
                    var _local9:GenericButton;
                    var _local10:GenericButton;
                    var _local11:GenericButton;
                    mc.addFrameScript(0, null, false, false);
                    hideAllUIElements(compId);
                    var _local1:Number = m_xpInitY;
                    if (isLimitedEdition(compId, index)){
                        if (!isMysteryItem(compId, index)){
                            turnOnLimitedIcon(m_data[(index + compId)].limitedIcon, m_tiles[compId]);
                        } else {
                            turnOnLimitedIcon("", m_tiles[compId]);
                        };
                        m_tiles[compId].timeLeft_tf.visible = true;
                        m_tiles[compId].timeLeft_tf.text = m_data[(index + compId)].limitedTimeLeft;
                        m_tiles[compId].limited_tf.visible = true;
                        m_tiles[compId].limited_tf.text = ZLoc.t("Dialogs", "LimitedText");
                        m_tiles[compId].brownBorder_mc.visible = true;
                    } else {
                        m_tiles[compId].timeLeft_tf.visible = false;
                        m_tiles[compId].limited_tf.visible = false;
                        turnOnLimitedIcon("", m_tiles[compId]);
                    };
                    if (hasWhatIsThisButton(compId, index)){
                        m_tiles[compId].whatisthis_mc.visible = true;
                        _local2 = new GenericButton(m_tiles[compId].whatisthis_mc, onShowWhatIsThisDialog, "", ("gb_WhatIsThis" + compId));
                        _local2.buttonValue = compId.toString();
                        m_tiles[compId].whatisthis_mc.value = compId.toString();
                        m_tiles[compId].whatisthis_bt = _local2;
                    };
                    if (m_data[(index + compId)]){
                        if (m_data[(index + compId)].harvestTime.toString() != ""){
                            m_tiles[compId].growth_tf.visible = true;
                            _local3 = "GrowthDays";
                            _local4 = m_data[(index + compId)].harvestTime;
                            _local5 = "";
                            if (_local4 < 1){
                                _local3 = "GrowthHours";
                                _local6 = Global.gameSettings.getNumber("inGameDaySeconds");
                                _local4 = (((_local6 / 60) / 60) * _local4);
                                _local5 = _local4.toFixed(0);
                            } else {
                                _local5 = _local4.toString();
                            };
                            m_tiles[compId].growth_tf.text = ZLoc.t("Dialogs", _local3, {time:_local5});
                        } else {
                            m_tiles[compId].growth_tf.visible = false;
                        };
                        if (((m_data[(index + compId)].capacity) && (!((m_data[(index + compId)].capacity.toString() == ""))))){
                            m_tiles[compId].growth_tf.visible = true;
                            m_tiles[compId].growth_tf.text = ZLoc.t("Dialogs", "CapacityMarket", {capacity:m_data[(index + compId)].capacity.toString()});
                        };
                        if (m_tiles[compId].growth_tf.visible == false){
                            if (((m_tiles[0]) && (m_tiles[0].growth_tf))){
                                _local1 = m_tiles[0].growth_tf.y;
                            };
                        };
                        if (((((!((m_data[(index + compId)].coinYield.toString() == ""))) && (isSellable(m_data[(index + compId)].type, m_data[(index + compId)].subtype)))) && (!(isMysteryItem(compId, index))))){
                            m_tiles[compId].yield_tf.visible = true;
                            m_tiles[compId].yield_tf.text = ZLoc.t("Dialogs", "Yield", {coins:m_data[(index + compId)].coinYield});
                        };
                        if ((((m_data[(index + compId)].cost > 0)) || ((m_data[(index + compId)].cash > 0)))){
                            switch (m_data[(index + compId)].market.toString()){
                                case Market.COST_CASH:
                                    _local7 = Utilities.formatNumber(m_data[(index + compId)].cash);
                                    m_tiles[compId].costGroup_mc.cashIcon_mc.visible = true;
                                    m_tiles[compId].costGroup_mc.coinIcon_mc.visible = false;
                                    break;
                                case Market.COST_COINS:
                                default:
                                    _local7 = Utilities.formatNumber(m_data[(index + compId)].cost);
                                    m_tiles[compId].costGroup_mc.cashIcon_mc.visible = false;
                                    m_tiles[compId].costGroup_mc.coinIcon_mc.visible = true;
                            };
                            m_tiles[compId].costGroup_mc.cost_tf.text = _local7;
                            if (_local7.length > 2){
                                m_tiles[compId].costGroup_mc.x = (m_costOffset - (6 * (_local7.length - 2)));
                            } else {
                                m_tiles[compId].costGroup_mc.x = m_costOffset;
                            };
                            m_tiles[compId].costGroup_mc.visible = true;
                        };
                        if ((m_tiles[compId].presentGenericButton is GenericButton)){
                            _local8 = m_tiles[compId].presentGenericButton;
                            _local8.disabled = true;
                            m_tiles[compId].presentGenericButton = _local8;
                        };
                        if (m_data[(index + compId)].isPresent){
                            if (m_tiles[compId].buyAlt_bt){
                                m_tiles[compId].buyAlt_bt.visible = true;
                                _local9 = new GenericButton(m_tiles[compId].buyAlt_bt, onBuyClick, "", ("gb_BuyBtn" + compId));
                                _local9.disabled = m_tiles[compId].disabled;
                                m_tiles[compId].genericButton = _local9;
                            };
                            if (m_tiles[compId].present_bt){
                                m_tiles[compId].present_bt.visible = true;
                                _local10 = new GenericButton(m_tiles[compId].present_bt, onPresentClick, "", ("gb_PresentBtn" + compId));
                                _local10.disabled = m_tiles[compId].disabled;
                                m_tiles[compId].presentGenericButton = _local10;
                            };
                        } else {
                            if (m_tiles[compId].buy_bt){
                                m_tiles[compId].buy_bt.visible = true;
                                _local11 = new GenericButton(m_tiles[compId].buy_bt, onBuyClick, "", ("gb_BuyBtn" + compId));
                                _local11.disabled = m_tiles[compId].disabled;
                                m_tiles[compId].genericButton = _local11;
                            };
                        };
                        if (((((((m_data[(index + compId)].xpGained) && (!((m_data[(index + compId)].xpGained.toString() == ""))))) && (isSellable(m_data[(index + compId)].type, m_data[(index + compId)].subtype)))) && (!(isMysteryItem(compId, index))))){
                            m_tiles[compId].xp_tf.visible = true;
                            m_tiles[compId].xp_tf.text = ZLoc.t("Dialogs", "XPGained", {experience:m_data[(index + compId)].xpGained});
                        };
                        m_tiles[compId].xp_tf.y = _local1;
                        setupMasteryDisplay(compId, index);
                        m_tiles[compId].itemTitle_tf.text = m_data[(index + compId)].localizedName;
                    };
                    if (hasWhatIsThisButton(compId, index)){
                        m_tiles[compId].growth_tf.visible = false;
                        m_tiles[compId].yield_tf.visible = false;
                        m_tiles[compId].xp_tf.visible = false;
                    };
                });
                mc.addFrameScript(1, function ():void{
                    var _local2:String;
                    var _local3:XML;
                    mc.addFrameScript(1, null, false, false);
                    hideAllUIElements(compId);
                    if (isLimitedEdition(compId, index)){
                        if (!isMysteryItem(compId, index)){
                            turnOnLimitedIcon(m_data[(index + compId)].limitedIcon, m_tiles[compId]);
                        } else {
                            turnOnLimitedIcon("", m_tiles[compId]);
                        };
                        m_tiles[compId].limited_tf.visible = true;
                        m_tiles[compId].limited_tf.text = ZLoc.t("Dialogs", "LimitedText");
                        m_tiles[compId].brownBorder_mc.visible = true;
                    } else {
                        m_tiles[compId].limited_tf.visible = false;
                        turnOnLimitedIcon("", m_tiles[compId]);
                    };
                    if ((((m_data[(index + compId)].cost > 0)) || ((m_data[(index + compId)].cash > 0)))){
                        switch (m_data[(index + compId)].market.toString()){
                            case Market.COST_CASH:
                                _local2 = Utilities.formatNumber(m_data[(index + compId)].cash);
                                m_tiles[compId].costGroup_mc.cashIcon_mc.visible = true;
                                m_tiles[compId].costGroup_mc.coinIcon_mc.visible = false;
                                break;
                            case Market.COST_COINS:
                            default:
                                _local2 = Utilities.formatNumber(m_data[(index + compId)].cost);
                                m_tiles[compId].costGroup_mc.cashIcon_mc.visible = false;
                                m_tiles[compId].costGroup_mc.coinIcon_mc.visible = true;
                        };
                        m_tiles[compId].costGroup_mc.cost_tf.text = _local2;
                        if (_local2.length > 2){
                            m_tiles[compId].costGroup_mc.x = (m_costOffset - (6 * (_local2.length - 2)));
                        } else {
                            m_tiles[compId].costGroup_mc.x = m_costOffset;
                        };
                        m_tiles[compId].costGroup_mc.visible = true;
                    };
                    var _local1 = "";
                    if (Global.player.checkItemLimit(m_data[(index + compId)].name)){
                        _local3 = Global.gameSettings.getItemXMLByName(m_data[(index + compId)].name);
                        _local1 = ZLoc.t("Dialogs", "LimitHit", {limit:_local3.limit});
                    } else {
                        switch (m_data[(index + compId)].unlock.toString()){
                            case Item.UNLOCK_LOCKED:
                                _local1 = ZLoc.t("Dialogs", "ComingSoon");
                                break;
                            case Item.UNLOCK_LEVEL:
                                _local1 = ZLoc.t("Dialogs", "LevelNeeded", {amount:m_data[(index + compId)].requiredLevel});
                                break;
                            case Item.UNLOCK_NEIGHBOR:
                                _local1 = ZLoc.t("Dialogs", "NeighborsNeeded", {amount:m_data[(index + compId)].minNeighbors});
                                break;
                            case Item.UNLOCK_PERMITS:
                                _local1 = ZLoc.t("Dialogs", "PermitsNeeded", {amount2:ExpansionManager.instance.getNextExpansionPermitRequirement()});
                                break;
                            default:
                                _local1 = ZLoc.t("Dialogs", "LevelNeeded", {amount:m_data[(index + compId)].requiredLevel});
                        };
                    };
                    m_tiles[compId].level_tf.text = _local1;
                    m_tiles[compId].level_tf.visible = true;
                    m_tiles[compId].locked_mc.visible = true;
                    m_tiles[compId].locked_tf.visible = true;
                    m_tiles[compId].locked_tf.text = ZLoc.t("Dialogs", "Locked");
                    m_tiles[compId].buy_tf.text = ZLoc.t("Dialogs", "Buy");
                    m_tiles[compId].itemTitle_tf.text = m_data[(index + compId)].localizedName;
                });
                mc.addFrameScript(2, function ():void{
                    var _local1:GenericButton;
                    mc.addFrameScript(2, null, false, false);
                    hideAllUIElements(compId);
                    if (isLimitedEdition(compId, index)){
                        if (!isMysteryItem(compId, index)){
                            turnOnLimitedIcon(m_data[(index + compId)].limitedIcon, m_tiles[compId]);
                        } else {
                            turnOnLimitedIcon("", m_tiles[compId]);
                        };
                        m_tiles[compId].limitedClock_mc.visible = SHOW_LIMITED_CLOCK;
                        m_tiles[compId].timeLeft_tf.text = m_data[(index + compId)].limitedTimeLeft;
                        m_tiles[compId].limited_tf.text = ZLoc.t("Dialogs", "LimitedText");
                        m_tiles[compId].brownBorder_mc.visible = true;
                    } else {
                        m_tiles[compId].limitedClock_mc.visible = false;
                        m_tiles[compId].limited_tf.visible = false;
                        turnOnLimitedIcon("", m_tiles[compId]);
                    };
                    if (hasWhatIsThisButton(compId, index)){
                        m_tiles[compId].whatisthis_mc.visible = true;
                        _local1 = new GenericButton(m_tiles[compId].whatisthis_mc, onShowWhatIsThisDialog);
                        _local1.buttonValue = compId.toString();
                        m_tiles[compId].whatisthis_mc.value = compId.toString();
                        m_tiles[compId].whatisthis_bt = _local1;
                    };
                    m_tiles[compId].locked_mc.visible = true;
                    m_tiles[compId].locked_tf.visible = true;
                    m_tiles[compId].locked_tf.text = ZLoc.t("Dialogs", "Locked");
                    m_tiles[compId].add_neighbor_bt.visible = true;
                    m_tiles[compId].neighbor_tf.visible = true;
                    m_tiles[compId].neighbor_tf.text = ZLoc.t("Dialogs", "NeighborsNeeded", {amount:m_data[(index + compId)].minNeighbors});
                    m_tiles[compId].add_neighbor_bt.addEventListener(MouseEvent.CLICK, onAddNeighborClick);
                    m_tiles[compId].itemTitle_tf.text = m_data[(index + compId)].localizedName;
                });
                mc.addFrameScript(3, function ():void{
                    mc.addFrameScript(3, null, false, false);
                    hideAllUIElements(compId);
                    turnOnLimitedIcon("", m_tiles[compId]);
                    m_tiles[compId].itemTitle_tf.text = m_data[(index + compId)].localizedName;
                    m_tiles[compId].buy_bt.visible = true;
                    var _local1:String = Utilities.formatNumber(m_data[(index + compId)].unlockCost);
                    m_tiles[compId].costGroup_mc.cost_tf.text = _local1;
                    m_tiles[compId].costGroup_mc.cashIcon_mc.visible = true;
                    m_tiles[compId].costGroup_mc.coinIcon_mc.visible = false;
                    m_tiles[compId].costGroup_mc.visible = true;
                });
                mc.addFrameScript(4, function ():void{
                    var gb:* = null;
                    var harvestLocStr:* = null;
                    var harvestTime:* = NaN;
                    var harvestTimeStr:* = null;
                    var dayInSeconds:* = NaN;
                    mc.addFrameScript(4, null, false, false);
                    hideAllUIElements(compId);
                    var sweetSeedsButton:* = new GameSprite();
                    sweetSeedsButton.addChild(m_tiles[compId].sweetSeedsInfo_bt);
                    m_tiles[compId].addChild(sweetSeedsButton);
                    var tooltip:* = new ToolTip();
                    tooltip.attachToolTip(sweetSeedsButton);
                    sweetSeedsButton.toolTip = ZLoc.t("Dialogs", "TooltipSeeds");
                    m_tiles[compId].sweetSeedsInfo_bt.addEventListener(MouseEvent.CLICK, function (_arg1:Event):void{
                        GlobalEngine.socialNetwork.redirect("seedsforhaiti.php", null, "_blank");
                    });
                    if (m_tiles[compId].buy_bt){
                        gb = new GenericButton(m_tiles[compId].buy_bt, onBuyClick, "", ("gb_BuyBtn" + compId));
                        gb.disabled = m_tiles[compId].disabled;
                        m_tiles[compId].genericButton = gb;
                    };
                    var name:* = m_data[(index + compId)].name;
                    var licenseHeld:* = Global.player.licenses[name];
                    var currentTime:* = (GlobalEngine.getTimer() * 0.001);
                    var delta:* = (licenseHeld - currentTime);
                    var expiresValue:* = Math.floor((delta / 60));
                    if (expiresValue < 60){
                        m_tiles[compId].greenexpires_tf.text = ZLoc.t("Dialogs", "ExpiresImmediately");
                    } else {
                        if ((expiresValue / 60) < 24){
                            m_tiles[compId].greenexpires_tf.text = ZLoc.t("Dialogs", "ExpiresHours", {time:Math.ceil((expiresValue / 60))});
                        } else {
                            m_tiles[compId].greenexpires_tf.text = ZLoc.t("Dialogs", "ExpiresDays", {time:Math.ceil(((expiresValue / 60) / 24))});
                        };
                    };
                    m_tiles[compId].greenexpires_tf.visible = true;
                    if (((!((m_data[(index + compId)].coinYield.toString() == ""))) && (isSellable(m_data[(index + compId)].type, m_data[(index + compId)].subtype)))){
                        m_tiles[compId].greenyield_tf.visible = true;
                        m_tiles[compId].greenyield_tf.text = ZLoc.t("Dialogs", "Yield", {coins:m_data[(index + compId)].coinYield});
                    };
                    if (m_data[(index + compId)].harvestTime.toString() != ""){
                        m_tiles[compId].greengrowth_tf.visible = true;
                        harvestLocStr = "GrowthDays";
                        harvestTime = m_data[(index + compId)].harvestTime;
                        harvestTimeStr = "";
                        if (harvestTime < 1){
                            harvestLocStr = "GrowthHours";
                            dayInSeconds = Global.gameSettings.getNumber("inGameDaySeconds");
                            harvestTime = (((dayInSeconds / 60) / 60) * harvestTime);
                            harvestTimeStr = harvestTime.toFixed(0);
                        } else {
                            harvestTimeStr = harvestTime.toString();
                        };
                        m_tiles[compId].greengrowth_tf.text = ZLoc.t("Dialogs", harvestLocStr, {time:harvestTimeStr});
                    };
                    if (((((m_data[(index + compId)].xpGained) && (!((m_data[(index + compId)].xpGained.toString() == ""))))) && (isSellable(m_data[(index + compId)].type, m_data[(index + compId)].subtype)))){
                        m_tiles[compId].greenxp_tf.visible = true;
                        m_tiles[compId].greenxp_tf.text = ZLoc.t("Dialogs", "XPGained", {experience:m_data[(index + compId)].xpGained});
                    };
                    m_tiles[compId].buy_bt.visible = true;
                    var costStr:* = Utilities.formatNumber(m_data[(index + compId)].cost);
                    m_tiles[compId].costGroup_mc.cost_tf.text = costStr;
                    m_tiles[compId].costGroup_mc.cashIcon_mc.visible = false;
                    m_tiles[compId].costGroup_mc.coinIcon_mc.visible = true;
                    m_tiles[compId].costGroup_mc.visible = true;
                    m_tiles[compId].itemTitle_tf.text = m_data[(index + compId)].localizedName;
                });
                m_tiles[compId].visible = true;
                if (m_tiles[compId].itemTitle_tf){
                    m_tiles[compId].itemTitle_tf.text = m_data[(index + compId)].localizedName;
                };
                if (((((!(Global.player.checkItemLimit(m_data[(index + compId)].name))) && (Global.player.checkGate(m_data[(index + compId)].unlock, m_data[(index + compId)].name)))) && (!(m_data[(index + compId)].unlockCost)))){
                    if ((((mc.currentFrame == 4)) || ((mc.currentFrame == 5)))){
                        mc.gotoAndStop(mc.totalFrames);
                    };
                    mc.gotoAndStop(1);
                    m_tiles[compId].disabled = false;
                } else {
                    if (((m_data[(index + compId)].unlockCost) && ((m_data[(index + compId)].unlockCost > 0)))){
                        name = m_data[(index + compId)].name;
                        licenseHeld = 0;
                        currentTime = (GlobalEngine.getTimer() / 1000);
                        if (Global.player.licenses[name]){
                            licenseHeld = Global.player.licenses[name];
                        };
                        delta = (licenseHeld - currentTime);
                        if (((!((licenseHeld == 0))) && ((delta > -10)))){
                            mc.gotoAndStop(5);
                            m_tiles[compId].disabled = false;
                        } else {
                            if (licenseHeld > 0){
                                GameTransactionManager.addTransaction(new TExpireLicense(name));
                            };
                            mc.gotoAndStop(4);
                            m_tiles[compId].disabled = false;
                        };
                    } else {
                        neighborSuccess = Global.player.checkNeighbors(m_data[(index + compId)].minNeighbors);
                        if (Global.player.checkItemLimit(m_data[(index + compId)].name)){
                            mc.gotoAndStop(2);
                            m_tiles[compId].disabled = true;
                        } else {
                            switch (m_data[(index + compId)].unlock.toString()){
                                case Item.UNLOCK_NEIGHBOR:
                                    levelSuccess = Global.player.checkLevel(m_data[(index + compId)].requiredLevel);
                                    if (neighborSuccess){
                                        mc.gotoAndStop(2);
                                    } else {
                                        mc.gotoAndStop(3);
                                    };
                                    m_tiles[compId].disabled = true;
                                    break;
                                case Item.UNLOCK_LEVEL:
                                default:
                                    mc.gotoAndStop(2);
                                    m_tiles[compId].disabled = true;
                            };
                        };
                    };
                };
                if (m_tiles[compId].genericButton){
                    m_tiles[compId].genericButton.disabled = m_tiles[compId].disabled;
                };
                tileSet = m_tileSet;
                url = Global.gameSettings.getImageByName(m_data[(index + compId)].name, "icon");
                icon = LoadingManager.load(url, function (_arg1:Event):void{
                    var _local2:*;
                    var _local3:*;
                    var _local4:*;
                    if (((((((icon) && (icon.content))) && ((m_tileSet == tileSet)))) && ((m_tileLoaders[compId].url == _arg1.target.url)))){
                        Utilities.removeAllChildren(mc.icon);
                        _local2 = icon.content;
                        _local3 = 1;
                        _local4 = 1;
                        if (m_tiles[0] != null){
                            _local3 = (1 / m_tiles[0].scaleX);
                            _local4 = (1 / m_tiles[0].scaleY);
                        };
                        _local2.width = (50 * _local3);
                        _local2.height = (50 * _local4);
                        mc.icon.addChild(_local2);
                        mc.icon.x = (m_iconOffset + 3);
                    };
                });
                this.m_tileLoaders[compId] = icon.contentLoaderInfo;
            };
        }
        private function onGetCoinsClick(_arg1:Event):void{
            GlobalEngine.socialNetwork.redirect("money.php?ref=marketDialogGetCoins");
        }
        private function loadPlantingSounds():void{
            SoundManager.addSound("plant1", Global.getAssetURL("assets/sounds/actions/sfx_plant_01.mp3"), false);
            SoundManager.addSound("plant2", Global.getAssetURL("assets/sounds/actions/sfx_plant_02.mp3"), false);
            SoundManager.addSound("plant3", Global.getAssetURL("assets/sounds/actions/sfx_plant_03.mp3"), false);
            m_soundLoaded = true;
        }
        private function onCloseClick(_arg1:MouseEvent, _arg2:Boolean=false):void{
            var gb:* = null;
            var event:* = _arg1;
            var isBuy:Boolean = _arg2;
            removeTiles(false);
            m_window.close_bt.removeEventListener(MouseEvent.CLICK, this.onCloseClick);
            this.topButtons.forEach(function (_arg1:MovieClip):void{
                _arg1.removeEventListener(MouseEvent.CLICK, onMenuBarClick);
            });
            this.subcatButtons.forEach(function (_arg1:MovieClip):void{
                _arg1.removeEventListener(MouseEvent.CLICK, onSubMenuBarClick);
            });
            for each (gb in this.topButtons) {
                gb.turnOff();
            };
            for each (gb in this.subcatButtons) {
                gb.turnOff();
            };
            m_window.arrowLt_bt.removeEventListener(MouseEvent.CLICK, onLtArrowClick);
            m_window.arrowRt_bt.removeEventListener(MouseEvent.CLICK, onRtArrowClick);
            if (event){
                event.stopPropagation();
            };
            this.count("close");
            this.close();
            dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
            if (this.m_onCloseClickCallback != null){
                this.m_onCloseClickCallback(isBuy);
            };
        }
        override public function close():void{
            var _local1:Array;
            var _local2:Item;
            super.close();
            if (this.m_popFeedFlag){
                this.m_popFeedFlag = false;
                _local1 = [];
                _local1.push({
                    src:Global.getAssetURL("assets/newsfeed/sweetseedsforhaiti_newsfeed02_cb.png"),
                    href:("{SN_APP_URL}{creative:picture}" + this.m_rewardLink)
                });
                if (this.m_rewardLink){
                    _local2 = Global.gameSettings.getItemByName(this.m_rewardName);
                    GlobalEngine.socialNetwork.publishFeedStory("SweetSeedsHaiti", {
                        player_name:Global.player.snUser.firstName,
                        item_name:_local2.localizedName,
                        images:_local1,
                        reward_link:this.m_rewardLink,
                        subCategory:"sweet_seeds_haiti"
                    }, [], false);
                } else {
                    GlobalEngine.socialNetwork.publishFeedStory("SweetSeedsHaiti", {images:_local1}, [], false);
                };
            };
            if (WhatIsThisPopup.describeDialogOpen){
                this.m_whatIsThisDialog.close();
            };
        }
        private function onMenuBarClick(_arg1:MouseEvent, _arg2:String=null, _arg3:String="all"):void{
            var _local4:String;
            var _local5:GenericButton;
            var _local6:String;
            var _local7:int;
            if (_arg2 != null){
                _local4 = _arg2;
            } else {
                _local4 = _arg1.target.name.replace(/_bt/, "");
            };
            if (((!((_local4 == this.m_currentType))) || (!((_arg2 == null))))){
                removeTiles();
                this.m_subTypeIndex = 1;
                this.m_currentSubType = _arg3;
                for (_local6 in this.subcatButtons) {
                    _local5 = (this.subcatButtons[_local6] as GenericButton);
                    if (_local6 != this.m_currentSubType){
                        _local5.state = GenericButton.UPSTATE;
                    };
                };
                if (_arg3 == "all"){
                    _local5 = (this.subcatButtons["subcat1_bt"] as GenericButton);
                    _local5.state = GenericButton.HITSTATE;
                };
                this.pushNewData(_local4, this.m_currentSubType);
                this.m_lastClickedType = this.m_currentType;
                this.count("menuBarClick");
                this.m_allCurrentSubTypes = Global.gameSettings.getSubMenuItemsByMenuType(this.m_currentType);
                this.showSubCatButtons(this.m_allCurrentSubTypes);
                _local7 = 0;
                while ((((_local7 < NUM_SLOTS)) && ((_local7 < m_data.length)))) {
                    this.addComponent(_local7);
                    _local7++;
                };
            };
        }
        private function onSubMenuBarClick(_arg1:MouseEvent):void{
            var _local3:GenericButton;
            var _local4:String;
            var _local5:int;
            var _local2:int = parseInt(_arg1.target.name.replace(/subcat/, "").replace(/_bt/, ""));
            if (this.m_subTypeIndex != _local2){
                if (_local2 == 1){
                    this.m_currentSubType = "all";
                } else {
                    this.m_currentSubType = this.m_allCurrentSubTypes[(_local2 - 2)].@subtype;
                };
                if (this.m_allCurrentSubTypes[(_local2 - 2)].@comingSoon == "true"){
                    StatsManager.count(this.MARKET_COUNTER, "subcat", "flowers");
                    for (_local4 in this.subcatButtons) {
                        if (_local4 == _arg1.target.name){
                            _local3 = (this.subcatButtons[_local4] as GenericButton);
                            _local3.state = GenericButton.UPSTATE;
                        };
                    };
                    UI.displayPopup(new GenericDialog(ZLoc.t("Dialogs", "ComingSoon")), false);
                } else {
                    this.m_subTypeIndex = _local2;
                    for (_local4 in this.subcatButtons) {
                        if (_local4 != _arg1.target.name){
                            _local3 = (this.subcatButtons[_local4] as GenericButton);
                            _local3.state = GenericButton.UPSTATE;
                        };
                    };
                    removeTiles();
                    this.pushNewData(this.m_currentType, this.m_currentSubType);
                    this.m_lastClickedType = this.m_currentType;
                    this.count("subMenuBarClick");
                    _local5 = 0;
                    while ((((_local5 < NUM_SLOTS)) && ((_local5 < m_data.length)))) {
                        this.addComponent(_local5);
                        _local5++;
                    };
                };
            };
        }
        protected function showSubCatButtons(_arg1:XMLList):void{
            var _local2:int;
            var _local3:MovieClip;
            var _local4:int;
            var _local5:GenericButton;
            var _local6:String;
            var _local7:String;
            _local3 = (m_window["subcat1_bt"] as MovieClip);
            if (_arg1.length() < 1){
                _local3.visible = false;
                _local5 = (this.subcatButtons["subcat1_bt"] as GenericButton);
                _local5.turnOff();
            } else {
                _local3.visible = true;
                _local5 = (this.subcatButtons["subcat1_bt"] as GenericButton);
                _local5.turnOn();
            };
            if (_arg1 == null){
                _local4 = 0;
            } else {
                _local4 = Math.min((_arg1.length() + 1), NUM_SUBSLOTS);
            };
            _local2 = 2;
            while (_local2 <= _local4) {
                _local6 = (("subcat" + _local2) + "_bt");
                _local5 = (this.subcatButtons[_local6] as GenericButton);
                _local7 = ZLoc.t("Dialogs", (_arg1[(_local2 - 2)].@subtype + "_submenu"));
                _local5.text = _local7;
                _local5.turnOn();
                _local2++;
            };
            _local2 = (_local4 + 1);
            while (_local2 <= NUM_SUBSLOTS) {
                _local6 = (("subcat" + _local2) + "_bt");
                _local5 = (this.subcatButtons[_local6] as GenericButton);
                _local5.turnOff();
                _local2++;
            };
        }
        override protected function postRemoveTiles(_arg1:int):void{
            if (m_tiles[_arg1].buy_bt){
                m_tiles[_arg1].buy_bt.removeEventListener(MouseEvent.CLICK, this.onBuyClick);
            };
            if (m_tiles[_arg1].sweetSeedsInfo_bt){
                m_tiles[_arg1].sweetSeedsInfo_bt.visible = false;
            };
            if (m_tiles[_arg1].add_neighbor_bt){
                m_tiles[_arg1].add_neighbor_bt.removeEventListener(MouseEvent.CLICK, this.onAddNeighborClick);
            };
        }
        private function getItemXMLFromEvent(_arg1:MouseEvent):XML{
            var _local2:String;
            var _local3:int;
            if (_arg1 == null){
                if (this.m_buyTileNumber > 0){
                    _local3 = this.m_buyTileNumber;
                };
            } else {
                _local2 = String(_arg1.target.parent.name).replace(/tile/, "");
                _local3 = (int(_local2) - 1);
            };
            var _local4:int = (_local3 + (m_tileSet * NUM_SLOTS));
            var _local5:String = m_data[_local4].name;
            return (Global.gameSettings.getItemXMLByName(_local5));
        }
        private function onBuyFromPopupClick(_arg1:GenericPopupEvent):void{
            if (_arg1.button == GenericPopup.YES){
                this.onBuyClick(null);
            };
        }
        private function onBuyClick(_arg1:MouseEvent):void{
            var _local2:XML;
            var _local3:Boolean;
            var _local4:int;
            var _local5:int;
            var _local6:Boolean;
            var _local7:String;
            var _local8:String;
            var _local9:int;
            var _local10:Boolean;
            var _local11:Boolean;
            var _local12:String;
            var _local13:XMLList;
            var _local14:int;
            var _local15:XML;
            var _local16:int;
            var _local17:String;
            var _local18:XMLList;
            var _local19:XML;
            _local2 = this.getItemXMLFromEvent(_arg1);
            SoundManager.chooseAndPlaySound(["click1", "click2", "click3"]);
            if (_local2){
                _local3 = false;
                switch (_local2.@market.toString()){
                    case Market.COST_CASH:
                        _local4 = _local2.cash;
                        _local3 = Global.player.canBuyCash(_local4, false);
                        break;
                    case Market.COST_COINS:
                    default:
                        _local5 = _local2.cost;
                        _local3 = Global.player.canBuy(_local5, true);
                        if (!_local3){
                            this.onCloseClick(_arg1);
                        };
                };
                if (_local3 == true){
                    _local6 = true;
                    _local7 = _local2.@type;
                    _local8 = _local2.@subtype;
                    switch (_local7){
                        case "tool":
                            dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.EQUIPMENT, _local2.@name));
                            break;
                        case "contract":
                            dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.CONTRACT, _local2.@name));
                            break;
                        case "residence":
                            dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.RESIDENCE, _local2.@name));
                            break;
                        case "business":
                            dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.BUSINESS, _local2.@name));
                            break;
                        case "factory":
                        case "decoration":
                        case "road":
                        case "pier":
                        case "ship":
                            dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.GENERIC, _local2.@name));
                            break;
                        case "change_farm":
                            if (_local8 == "expand_farm"){
                                _local9 = Global.player.homeIslandSize;
                                _local10 = false;
                                _local11 = false;
                                _local12 = null;
                                _local13 = Global.gameSettings.getItemsByTypeXML("change_farm", "expand_farm");
                                _local14 = 0;
                                while (_local14 < _local13.length()) {
                                    _local15 = _local13[_local14];
                                    if (_local15.@size == _local9){
                                        _local11 = true;
                                    } else {
                                        if (_local11 == true){
                                            if (_local15.@size == _local2.@size){
                                                _local10 = true;
                                            } else {
                                                _local16 = 0;
                                                while (_local16 < m_data.length) {
                                                    if (m_data[_local16].subtype == "expand_farm"){
                                                        _local12 = m_data[_local16].localizedName;
                                                        break;
                                                    };
                                                    _local16++;
                                                };
                                            };
                                            break;
                                        };
                                    };
                                    _local14++;
                                };
                                if (_local10){
                                    dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.EXPAND_FARM, _local2.@name));
                                } else {
                                    _local18 = Global.gameSettings.getItemsByTypeXML("change_farm", "expand_farm");
                                    for each (_local19 in _local18) {
                                        if (int(_local19.@size) == (Global.player.homeIslandSize + 2)){
                                            _local17 = _local19.@name;
                                            break;
                                        };
                                    };
                                    _local6 = false;
                                    UI.displayMessage(ZLoc.t("Dialogs", "CantExpandFarm", {expansion:_local17}), GenericPopup.TYPE_OK, null, "", true);
                                };
                            };
                            break;
                    };
                    this.count(("buy_" + _local2.@name));
                    if (_local6 == true){
                        this.onCloseClick(_arg1, true);
                    };
                } else {
                    if (_local2.@market.toString() == Market.COST_CASH){
                        UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_CASH);
                        StatsManager.count("fv_cash_buy_fail", "view_popup");
                    } else {
                        if (_local2.@market.toString() == Market.COST_COINS){
                            UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_COINS);
                        };
                    };
                };
            };
        }
        protected function onPresentClick(_arg1:MouseEvent):void{
            this.onCloseClick(_arg1, true);
            var _local2:XML = this.getItemXMLFromEvent(_arg1);
            dispatchEvent(new MarketEvent(MarketEvent.MARKET_PRESENT, 0, _local2.@name));
            StatsManager.count("fv_buyableGift", "click_send");
        }
        private function onAddNeighborClick(_arg1:MouseEvent):void{
            var _local2:URLVariables = new URLVariables();
            var _local3:XML = this.getItemXMLFromEvent(_arg1);
            var _local4:String;
            if (_local3){
                switch (this.m_currentType){
                    case "change_farm":
                        _local2.requestType = "expandFarm";
                        _local2.farm = _local3.@name;
                        _local2.creative = ("market_" + _local3.@size);
                        _local4 = "invite.php?ref=neighborsExpansionPage&";
                        break;
                    case "building":
                        _local2.requestType = "building";
                        _local2.creative = ("building_" + _local3.@name);
                        _local4 = "invite.php?ref=neighborsExpansionPage&";
                        break;
                    case "tree":
                        _local2.requestType = "trees";
                        _local2.creative = ("tree_" + _local3.@name);
                        _local4 = "invite.php?ref=neighborsTreePage&";
                        break;
                    case "decoration":
                        _local2.requestType = "decoration";
                        _local2.creative = ("market_" + _local3.@size);
                        _local4 = "invite.php?ref=neighborsExpansionPage&";
                        break;
                    case "vehicle":
                        if (_local3.@type == "fuelcapacity"){
                            _local2.requestType = "fuelcapacity";
                            _local2.creative = ("fuelcapacity_" + _local3.@size);
                            _local4 = "invite.php?ref=neighborsExpansionPage&";
                        };
                        break;
                };
            };
            if (_local4){
                GlobalEngine.socialNetwork.redirect(_local4, _local2);
            };
        }
        private function displayStatus(_arg1:MouseEvent, _arg2:String):void{
            var _local3:Point = new Point(_arg1.stageX, _arg1.stageY);
            if (m_tiles.length > 0){
                _local3.y = (_local3.y - m_tiles[0].height);
            };
            _local3 = IsoMath.viewportToStage(_local3);
            UI.displayStatus(_arg2, _local3.x, _local3.y);
        }
        private function count(_arg1:String=null, _arg2:String=null):void{
            if (_arg2 == null){
                _arg2 = this.m_lastClickedType;
            };
            StatsManager.count(this.MARKET_COUNTER, this.m_viewSource, _arg2, _arg1, this.m_currentSubType);
        }
        private function isSellable(_arg1:String, _arg2:String):Boolean{
            var _local3:Boolean;
            switch (_arg1){
                case "fuel":
                case "fuelcapacity":
                    _local3 = false;
                    break;
                case "tool":
                    _local3 = !((_arg2 == "equipment"));
                    break;
            };
            return (_local3);
        }
        private function onShowWhatIsThisDialog(_arg1:MouseEvent):void{
            var _local2:XML;
            var _local3:XML;
            this.m_buyTileNumber = int(_arg1.currentTarget.parent.whatisthis_mc.value);
            if (!WhatIsThisPopup.describeDialogOpen){
                _local2 = this.getItemXMLFromEvent(null);
                this.m_whatIsThisDialog = new WhatIsThisPopup(_local2, this.onBuyFromPopupClick);
                UI.displayPopup(this.m_whatIsThisDialog, false, "whatIsThisDescription", true);
                _local3 = this.getItemXMLFromEvent(_arg1);
                StatsManager.count("Market", "actionMenu", this.m_currentType, "click_questionmark", _local3.@name);
            };
        }

    }
}//package Display 
